package com.cskaoyan.service;

import com.cskaoyan.bean.MarketRegion;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketRegionMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author stone
 * @date 2023/05/29 10:55
 */
public class AdminRegionServiceImpl implements AdminRegionService {
    @Override
    public BaseRespVo allRegionList() {
        // 封装对应的BaseRespVo

        // 通常里面的data 是 CommonData的封装，但是也有不是CommonData，需要大家具体分析
        // 这个里面的业务代码 → MyBatis第4天 → 作业 → 两种不同的参考代码 1.MyBatis多表查询 2.Stream

        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketRegionMapper regionMapper = sqlSession.getMapper(MarketRegionMapper.class);

//        MarketRegionExample example = new MarketRegionExample();
//        MarketRegionExample.Criteria criteria=example.createCriteria();

        List<MarketRegion> marketRegions = regionMapper.selectByExample();

        PageInfo pageInfo = new PageInfo(marketRegions);
        sqlSession.close();// 不要忘记
        return BaseRespVo.ok(CommonData.data(pageInfo));
    }
}
